package com.ruoyi.service;

import com.ruoyi.entity.SxfPriceParkingSpace;
import com.ruoyi.mapper.SxfPriceParkingSpaceMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.SxfPriceParkingSpaceFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 价格体系与车位关系表 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-10-20
 */
@Service
public class SxfPriceParkingSpaceService extends ServiceImpl<SxfPriceParkingSpaceMapper, SxfPriceParkingSpace> {

	public ResponseData create(SxfPriceParkingSpaceFrom sxfPriceParkingSpace) {
		SxfPriceParkingSpace entity = transformationFrom(sxfPriceParkingSpace);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(SxfPriceParkingSpaceFrom sxfPriceParkingSpace) {
		if(findById(sxfPriceParkingSpace.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfPriceParkingSpace entity = transformationFrom(sxfPriceParkingSpace);
		entity.setId(sxfPriceParkingSpace.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public SxfPriceParkingSpace transformationFrom(SxfPriceParkingSpaceFrom sxfPriceParkingSpace) {
		SxfPriceParkingSpace entity = new SxfPriceParkingSpace();
		entity.setPlCode(sxfPriceParkingSpace.getPlCode());
		entity.setSpaceId(sxfPriceParkingSpace.getSpaceId());
		entity.setPriceSystemCode(sxfPriceParkingSpace.getPriceSystemCode());
		entity.setValidateTime(sxfPriceParkingSpace.getValidateTime());
		entity.setIsDeleted(sxfPriceParkingSpace.getIsDeleted());
		entity.setSpaceProperty(sxfPriceParkingSpace.getSpaceProperty());
		entity.setWithdrawChannel(sxfPriceParkingSpace.getWithdrawChannel());
		entity.setCreator(sxfPriceParkingSpace.getCreator());
		entity.setCreateTime(sxfPriceParkingSpace.getCreateTime());
		entity.setModifier(sxfPriceParkingSpace.getModifier());
		entity.setModifyTime(sxfPriceParkingSpace.getModifyTime());
		entity.setPriceId(sxfPriceParkingSpace.getPriceId());
		return entity;
	}

	public SxfPriceParkingSpaceFrom transformationBean(SxfPriceParkingSpace sxfPriceParkingSpace) {
		SxfPriceParkingSpaceFrom from = new SxfPriceParkingSpaceFrom();
		from.setPlCode(sxfPriceParkingSpace.getPlCode());
		from.setSpaceId(sxfPriceParkingSpace.getSpaceId());
		from.setPriceSystemCode(sxfPriceParkingSpace.getPriceSystemCode());
		from.setValidateTime(sxfPriceParkingSpace.getValidateTime());
		from.setIsDeleted(sxfPriceParkingSpace.getIsDeleted());
		from.setSpaceProperty(sxfPriceParkingSpace.getSpaceProperty());
		from.setWithdrawChannel(sxfPriceParkingSpace.getWithdrawChannel());
		from.setCreator(sxfPriceParkingSpace.getCreator());
		from.setCreateTime(sxfPriceParkingSpace.getCreateTime());
		from.setModifier(sxfPriceParkingSpace.getModifier());
		from.setModifyTime(sxfPriceParkingSpace.getModifyTime());
		from.setPriceId(sxfPriceParkingSpace.getPriceId());

		return from;
	}

	
	public SxfPriceParkingSpaceFrom findById(String id) {
		SxfPriceParkingSpace entity = this.getOne(new QueryWrapper<SxfPriceParkingSpace>().lambda()
				.eq(SxfPriceParkingSpace::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfPriceParkingSpace sxfPriceParkingSpace = new SxfPriceParkingSpace();
		sxfPriceParkingSpace.setId(id);
		this.updateById(sxfPriceParkingSpace);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, SxfPriceParkingSpaceFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<SxfPriceParkingSpace>().lambda()
				.eq(StringUtils.isNotEmpty(ibean.getPlCode()), SxfPriceParkingSpace::getPlCode, ibean.getPlCode())
				.eq(ibean.getSpaceId() != null, SxfPriceParkingSpace::getSpaceId, ibean.getSpaceId())
				.eq(StringUtils.isNotEmpty(ibean.getPriceSystemCode()), SxfPriceParkingSpace::getPriceSystemCode, ibean.getPriceSystemCode())
				.eq(ibean.getValidateTime() != null, SxfPriceParkingSpace::getValidateTime, ibean.getValidateTime())
				.eq(StringUtils.isNotEmpty(ibean.getIsDeleted()), SxfPriceParkingSpace::getIsDeleted, ibean.getIsDeleted())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceProperty()), SxfPriceParkingSpace::getSpaceProperty, ibean.getSpaceProperty())
				.eq(StringUtils.isNotEmpty(ibean.getWithdrawChannel()), SxfPriceParkingSpace::getWithdrawChannel, ibean.getWithdrawChannel())
				.eq(ibean.getCreator() != null, SxfPriceParkingSpace::getCreator, ibean.getCreator())
				.eq(ibean.getCreateTime() != null, SxfPriceParkingSpace::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifier() != null, SxfPriceParkingSpace::getModifier, ibean.getModifier())
				.eq(ibean.getModifyTime() != null, SxfPriceParkingSpace::getModifyTime, ibean.getModifyTime())
				.eq(StringUtils.isNotEmpty(ibean.getPriceId()), SxfPriceParkingSpace::getPriceId, ibean.getPriceId())
				);
	}
}
